package adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.deep_tools.ecdc.R;
import java.util.List;

import transformer.CustomizeDetailEnty;
import utils.DensityUtil;

/**
 * ViewPager适配器
 * Create by: chenwei.li
 * Date: 2017/12/8
 * time: 15:17
 * Email: lichenwei.me@foxmail.com
 */

public class CustomizeAdapter extends BaseAdapter {
    private List<CustomizeDetailEnty> customizeDetailEntyList;
    private Activity activity;
    public CustomizeAdapter (List<CustomizeDetailEnty> customizeDetailEntyList,Activity activity){
        this.customizeDetailEntyList=customizeDetailEntyList;
        this.activity=activity;
    }

    @Override
    public int getCount() {
        if(customizeDetailEntyList==null||customizeDetailEntyList.size()<=0){
            return 0;
        }
        return customizeDetailEntyList.size();
    }

    public void setUpdate(List<CustomizeDetailEnty> customizeDetailEntyList){
        this.customizeDetailEntyList=customizeDetailEntyList;
         notifyDataSetChanged();;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        View view = null;
        final ViewHolder mHolder;
        if (convertView == null) {
            mHolder = new ViewHolder();
            view = LayoutInflater.from(activity).inflate(R.layout.item_customize_adapter, null);
            mHolder.imageView_item_customize_adapter=view.findViewById(R.id.imageView_item_customize_adapter);
            mHolder.textView_item_customize_adapter=view.findViewById(R.id.textView_item_customize_adapter);
            view.setTag(mHolder);

        }else{
            view = convertView;
            mHolder = (ViewHolder) view.getTag();
        }


        mHolder.imageView_item_customize_adapter.setImageResource(customizeDetailEntyList.get(position).imageResourceId);
        mHolder.textView_item_customize_adapter.setText(customizeDetailEntyList.get(position).order);

        if(customizeDetailEntyList.get(position).order.equals("0")){
            mHolder.textView_item_customize_adapter.setVisibility(View.INVISIBLE);
            mHolder.imageView_item_customize_adapter.setBackgroundResource(R.drawable.circle_watch_face_style2);

        }else{
            mHolder.textView_item_customize_adapter.setVisibility(View.VISIBLE);
            mHolder.imageView_item_customize_adapter.setBackgroundResource(R.drawable.circle_watch_face_style);


        }

        return view;
    }


    class ViewHolder {
        ImageView imageView_item_customize_adapter;
        TextView textView_item_customize_adapter;
    }

}
